package @@packageName@@;

import java.util.Date;

import com.google.gwt.json.client.*;

public class ObjectJsonizer {
    public static Character toJavaChar(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        JSONString jsonString = value.isString();
        if (jsonString == null) {
            throw new JSONException("expected JSONNull or JSONString");
        } else {
            return new Character(jsonString.stringValue().charAt(0));
        }
    }

    public static String toJavaString(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        JSONString jsonString = value.isString();
        if (jsonString == null) {
            throw new JSONException("expected JSONNull or JSONString");
        } else {
            return jsonString.stringValue();
        }
    }

    public static Boolean toJavaBoolean(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        JSONBoolean jsonBoolean = value.isBoolean();
        if (jsonBoolean == null) {
            throw new JSONException("expected JSONNull or JSONBoolean");
        } else {
            return jsonBoolean.booleanValue() ? Boolean.TRUE : Boolean.FALSE;
        }
    }

    public static Short toJavaShort(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Short(PrimitiveJsonizer.toJavaShort(value));
    }

    public static Integer toJavaInteger(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Integer(PrimitiveJsonizer.toJavaInteger(value));
    }

    public static Long toJavaLong(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Long(PrimitiveJsonizer.toJavaLong(value));
    }

    public static Float toJavaFloat(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Float(PrimitiveJsonizer.toJavaFloat(value));
    }

    public static Double toJavaDouble(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Double(PrimitiveJsonizer.toJavaDouble(value));
    }

    public static Date toJavaDate(JSONValue value) {
        if (value.isNull() != null) {
            return null;
        }

        return new Date(PrimitiveJsonizer.toJavaLong(value));
    }

    public static JSONValue toJsonChar(Character arg0) {
        if (arg0 == null) {
            return JSONNull.getInstance();
        } else {
            return new JSONString(arg0.toString());
        }
    }

    public static JSONValue toJsonString(String arg0) {
        if (arg0 == null) {
            return JSONNull.getInstance();
        } else {
            return new JSONString(arg0);
        }
    }

    public static JSONValue toJsonBoolean(Boolean arg0) {
        if (arg0 == null) {
            return JSONNull.getInstance();
        } else {
            return JSONBoolean.getInstance(arg0.booleanValue());
        }
    }

    public static JSONValue toJsonShort(Short arg0) {
        return (arg0 == null) ? JSONNull.getInstance() : new JSONString(arg0.toString());
    }

    public static JSONValue toJsonInteger(Integer arg0) {
        return (arg0 == null) ? JSONNull.getInstance() : new JSONString(arg0.toString());
    }

    public static JSONValue toJsonLong(Long arg0) {
        return (arg0 == null) ? JSONNull.getInstance() : new JSONString(arg0.toString());
    }

    public static JSONValue toJsonFloat(Float arg0) {
        return (arg0 == null) ? JSONNull.getInstance() : new JSONString(arg0.toString());
    }

    public static JSONValue toJsonDouble(Double arg0) {
        return (arg0 == null) ? JSONNull.getInstance() : new JSONString(arg0.toString());
    }

    public static JSONValue toJsonDate(Date arg0) {
        if (arg0 == null) {
            return JSONNull.getInstance();
        } else {
            return new JSONNumber(arg0.getTime());
        }
    }
}
